<template>
	<view class="index-page with-tabbar" v-if="custom && loading">
		<!-- 页面主要内容区域 -->
		<view class="page-content">
			<!-- 5. 职位列表 -->
			<view class="job-list-section">
				<!-- 两级Tab结构 -->
				<view class="tabMian  bg-f7 pt-20 pl-20 pr-20 pb-20">
					<!-- 主分类 -->
					<view class="main-tabs  flex-center bg-fff bor-r16 pl-20 pr-20  lh-80">
						<view class="tabs-scroll">
							<text v-for="(tab, index) in jobTabs" :key="index" class="main-tab-item pb-1"
								:class="{ active: activeMainTab === index }" @click="selectMainTab(tab, index)">
								{{ tab.professionName }}
							</text>
						</view>
						<view class=" ml-auto  flex-center pl-10 box-shadow" @click="filterBtn">
							<div class="iconfont icon-shaixuan fontS30"></div>
							<div class="ml-10 ">筛选</div>
							<div v-if="filterParamNum">·{{ filterParamNum }}</div>
						</view>
					</view>


				</view>
				<div class="mt-130">
					<view class="job-card" v-for="(job, index) in jobList" :key="index" @click="goJobDetail(job)">
						<view class="card-top">
							<text class="job-title">{{ job.professionName || '' }}</text>
							<text class="job-salary">{{ job.salary }}{{ job.salaryMonth ? '·' + job.salaryMonth + '薪' :
								''
							}}</text>
						</view>
						<view class="card-company">
							<text>{{ job.companyName || '' }} {{ job.companySizeName || '' }}</text>
							<text class="card-company-location">{{ job.areaName || '' }}</text>
						</view>
						<view class="card-tags flex-center" v-if="job.postKey.length > 0">
							<div class="tag" v-for="tag in job.postKey.split(',')" :key="tag">{{ tag }}</div>
						</view>
						<view class="card-bottom">
							<view class="hr-info">
								<text class="hr-name">{{ job.creator || '' }}·{{ job.creatorPostName || '' }}</text>
							</view>
							<!-- <view class="online-status">
							<view class="dot"></view>
							<text>当前在线</text>
						</view> -->
						</view>
					</view>
					<view v-if="!noteFlag && !loadList" class="pt-20 pb-20 color-6d text-center fontS28">没有更多数据</view>
					<without v-if="loadList"></without>
				</div>

			</view>
		</view>


	</view>

</template>

<script>
import { resumeExpect, jobberQuery } from "@/api/index";

export default {
	data() {
		return {
			loading: false,
			loadList: false,
			custom: null,
			baseUrl: getApp().globalData.baseUrl,
			jobTabs: [],
			activeMainTab: 0,
			jobList: [],
			noteFlag: true,
			params: {
				pageNo: 1,
				pageSize: 6,
				professionIdList: [],
				isRecommend: 1

			},
			menuPages: [],
			filterParam: {},
			filterParamNum: 0

		};
	},

	computed: {
		userInfo() {
			console.log(this.$store.getters.userInfo)
			return this.$store.getters.userInfo || {};
		},
	},
	onPageScroll(e) {
		if (e.scrollTop > 3) {
			this.bgColor = '#fff'
			this.scrollPage = true
		} else {
			this.bgColor = 'transparent'
			this.scrollPage = false
		}
	},
	async onLoad() {
		this.custom = wx.getMenuButtonBoundingClientRect()

	},
	async onShow() {
		this.loading = false
		Object.assign(this.params, this.filterParam)
		this.params.pageNo = 1
		await this.getJobList()
		this.loading = true
		if (this.userInfo.userType) {
			await this.getResumeList()
		}
	},

	onReachBottom() {
		this.params.pageNo++;
		if (this.noteFlag) {
			this.getJobList();
		}


	},
	methods: {




		// 获取期望职位列表
		async getResumeList() {
			const {
				data
			} = await resumeExpect();
			data.unshift({
				professionName: '推荐',
				professionId: ''
			})
			this.jobTabs = data
		},

		// 获取职位列表
		async getJobList() {
			const {
				rows
			} = await jobberQuery(this.params);
			if (rows.length < this.params.pageSize) {
				this.noteFlag = false
			}
			this.jobList = this.params.pageNo === 1 ? rows : [...this.jobList, ...rows];
			if (this.jobList.length < 1) {
				this.loadList = true
			}
		},

		// 跳转到筛选页面
		filterBtn() {
			uni.navigateTo({
				url: `/pages/index/filter?filterP=${JSON.stringify(this.filterParam)}`
			})

		},
		// 跳转服务详情
		goDetail(type, item) {
			console.log(item)
			let id = ''
			if (type === 'banner') id = item.linkId
			if (type === 'serve') id = item.serveId
			uni.navigateTo({
				url: `/pages/service/serviceDetail?serveId=${id}`
			})

		},
		// 跳转职位详情
		goJobDetail(item) {

			uni.navigateTo({
				url: `/pages/position/detail?positionId=${item.positionId}`
			})
		},



		selectMainTab(tab, index) {
			if (index === 0) {
				this.params.isRecommend = 1
			} else {
				this.params.isRecommend = ''
			}

			this.activeMainTab = index;
			this.params.professionIdList = tab.professionId ? [tab.professionId] : []
			this.params.pageNo = 1
			this.getJobList()

		}
	}
};
</script>

<style lang="less" scoped>
@import url(home.less);

.tabMian {
	position: fixed;
	top: 0;
	left: 0;
	padding-top: 20upx;
	width: 100%;





}
</style>